package com.wmwj.hxlj.mapper;

import com.wmwj.hxlj.entity.ArticleLike;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ArticleLikeMapper {
    /**
     * 根据文章id和用户id查询点赞记录
     * @param articleId 文章id
     * @param userId 用户id
     * @return 点赞记录
     */
    @Select("SELECT * FROM article_like WHERE article_id = #{articleId} AND user_id = #{userId}")
    ArticleLike findLikeStatus(Long articleId, Long userId);

    /**
     * 根据文章id和用户id插入点赞记录
     * @param articleId 文章id
     * @param userId 用户id
     * @return 插入结果
     */
    @Insert("INSERT INTO article_like (article_id, user_id) VALUES (#{articleId}, #{userId})")
    int insertLikeStatus(Long articleId, Long userId);

    /**
     * 根据文章id和用户id删除点赞记录（软删除）
     * @param articleId 文章id
     * @param userId 用户id
     * @return 删除结果
     */
//    @Delete("DELETE FROM article_like WHERE article_id = #{articleId} AND user_id = #{userId}")
//    int deleteLikeStatus(Long articleId, Long userId);
    @Update("UPDATE article_like SET is_deleted = TRUE WHERE article_id = #{articleId} AND user_id = #{userId}")
    int deleteLikeStatus(Long articleId, Long userId);

    /**
     * 根据文章id和用户id插入点赞记录（软增加）
     * @param articleId 文章id
     * @param userId 用户id
     * @return 点赞记录
     */
    @Update("UPDATE article_like SET is_deleted = FALSE WHERE article_id = #{articleId} AND user_id = #{userId}")
    int insertLikeStatus2(Long articleId, Long userId);
}
